<?php
namespace app\yiluqianxing\home;

use think\Controller;
use think\Db;
use think\Request;
//点数相关
class Xiaochengxuorder extends Controller{

    //未确认定单列表
    function weiqueren($openid=''){
        $data=Db::table('dq_ylqx_order')
            ->where(['status'=>0])
            ->select();
        return $data;
    }

    //未确认定单列表
    function json_weiqueren($openid=''){
        $data=Db::table('dq_ylqx_order')
            ->where(['status'=>0])
            ->select();
        return json_encode($data);
    }

    //    用户兑换初审
    function duihuan($id,$openid){
        $goodinf=Db::table('dp_ylqx_goods')
            ->where('id',$id)
            ->find();
        $userinf=Db::table('dp_ylqx_user')
            ->where('openid',$openid)
            ->find();
        $point=new Xiaochengxupoint();
        $userinf['point']=$point->getUserPoint($openid);
        if($userinf['point']>=$goodinf['point'] && $goodinf['num']>0){
            $data['openid']=$openid;
            $data['goodsid']=$id;
            $data['point']=$goodinf['point'];
            echo json_encode(['code'=>1,'data'=>$data]);
        }
    }

    //用户带地址确认兑换
    function duihuan2(Request $request){
        $data=$request->param();
        $good=new Xiaochengxugoods();
        $goodinf=$good->goodsinf($data['goodid'],false);
        $data['point']=$goodinf['point'];
        $save=Db::table('dq_ylqx_order')
            ->insert($data);
        echo 1;
    }





    //获取所有用户点数排行

    //

}